<?php
/**
 * Soar Framework - Lightweight and simple to use PHP Framework
 *
 * Soar is free software and is distributed WITHOUT ANY WARRANTY
 *
 * @package Soar
 * @version 1.0 $Id: SoarSingleton.php 2 2012-04-06 21:50:33Z shay@shayanderson.com $
 * @copyright Copyright (c) 2012 ShayAnderson.com
 * @license http://www.gnu.org/licenses/gpl.html GPL License
 * @link http://www.shayanderson.com/projects/soar-php-framework.htm
 */

/**
 * Soar Framework Abstract Singleton Class
 * 
 * @package Soar
 * @name SoarSingleton
 * @author Shay Anderson 03.12
 * 
 * @example
 * class Example extends SoarSingleton
 * {
 *		public static function &getInstance()
 *		{
 *			parent::$_class_name = __CLASS__;
 *			return parent::getInstance();
 *		}
 * }
 */
abstract class SoarSingleton
{
	/**
	 * Instances collection
	 * 
	 * @var array
	 */
	private static $__instances = array();
	
	/**
	 * Instance class name
	 * 
	 * @var string
	 */
	protected static $_class_name;
	
	/**
	 * Init 
	 */
	protected function __construct()
	{
		// overridable
	}
	
	/**
	 * Do not allow 
	 */
	private function __clone(){}
	
	/**
	 * Get self instance (singleton)
	 *
	 * @return object
	 */
	public static function &getInstance()
	{
		$class_name = self::$_class_name;
		if(!isset(self::$__instances[$class_name]))
		{
			self::$__instances[$class_name] = new $class_name;
		}	
		return self::$__instances[$class_name];
	}
}
?>